﻿using System.Windows;
using System.Windows.Interactivity;
using CardPlay.Client.ViewModels;

namespace CardPlay.Client.Behaviors
{
    public class HotCueBehavior : Behavior<FrameworkElement>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.MouseEnter += OnMouseEnter;
            AssociatedObject.MouseLeave += OnMouseLeave;
        }

        protected override void OnDetaching()
        {
            AssociatedObject.MouseEnter -= OnMouseEnter;
            AssociatedObject.MouseLeave -= OnMouseLeave;
            base.OnDetaching();
        }

        void OnMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ShowHotState(true);
        }

        void OnMouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ShowHotState(false);
        }

        void ShowHotState(bool show)
        {
            var item = AssociatedObject.DataContext as IHaveHotState;
            if (item != null) item.InHotState = show;
        }
    }
}